package leetcode.editor.cn;

import java.util.*;
import leetcode.editor.common.*;

public class RotateArray {

  public static void main(String[] args) {
    Solution solution = new RotateArray().new Solution();
    // put your test code here
solution.rotate(new int[]{1, 2, 3, 4, 5, 6, 7}, 3);
  }
  // leetcode submit region end(Prohibit modification and deletion)

  // leetcode submit region begin(Prohibit modification and deletion)
  class Solution {
    public void rotate(int[] nums, int k) {
      int[] res = new int[nums.length];
      int n = nums.length;
      int index = k % n;

      int realIndex = n - index;
      int j = 0;
      // 移动需要挪动到头的
      while (realIndex < n) {
        res[j] = nums[realIndex];
        realIndex++;
        j++;
      }

      // 移动 剩下需要平移的
      int q=0;
      while (j<=n-1){
        res[j] = nums[q];
        j++;
        q++;
      }
      for (int i = 0; i < res.length; i++){
        nums[i] = res[i];
      }
      System.out.println(res);

    }
  }
}
